
const stockManage = {
  namespaced: true,
  state: () => {
    return {
      wmsScanList: [],
      wmsReturnScanList: [],// 退料数组
    }
  },
  mutations: {
    // 删除已提交的数据
    REACTSUBMITTEDWMSSCANLIST: (state, storeId) => {
      state.wmsScanList.forEach((element,index) => {
        if(element.storeId == storeId){
          state.wmsScanList.splice(index,1)
        }
      });
    },
    WMSSCANLIST: (state, params) => {
      if(state.wmsScanList.length == 0){
        let dict = {
          storeId:params.storeId,
          arr:[]
        }
        dict.arr.unshift(params)
        state.wmsScanList.push(dict)
      }else{
        // 用于筛选出相对应的storeId数组  如果有循环添加  如果没用保存新的
        let indexArr = state.wmsScanList.filter(x => x.storeId == params.storeId)
        if(!indexArr.length){
          let dict = {
            storeId:params.storeId,
            arr:[]
          }
          dict.arr.unshift(params)
          state.wmsScanList.push(dict)
        }else{
          state.wmsScanList.forEach(element => {
            if(element.storeId == params.storeId){
              element.arr.unshift(params)
            }
          });
        }
      }
    },
    DELWMSSCANLISTITEM: (state, params) => {
      // 删除以后重新赋值 
      let wmsScanList = state.wmsScanList;
      wmsScanList[params.i].arr.splice(params.index,1)
    },
    /**
     * 退料操作 保存删除
     * @param {*} state 
     * @param {*} params 
     */
    WMSRETURNSCANList: (state, params) => {
      state.wmsReturnScanList.unshift(params)
    },
    DELWMSSRETURNCANLISTITEM: (state, params) => {
      state.wmsReturnScanList.splice(params,1)
    },
    REACTRETURNlIST: (state, params)=>{
      state.wmsReturnScanList = []
    }
  },
  actions: {
    SetWmsScanList(context, params) {
      context.commit('WMSSCANLIST', params) 
    },
    delWmsScanListItem (context, params) {
      context.commit('DELWMSSCANLISTITEM', params) 
    },
    resetSubmittedWmsScanList (context, params) {
      context.commit('REACTSUBMITTEDWMSSCANLIST', params) 
    },
    /**
     * 退料操作
     * @param {*} context 
     * @param {*} params 
     */
    SetWmsReturnScanList (context, params) {
      context.commit('WMSRETURNSCANList', params) 
    },
    delWmsReturnScanListItem (context, params) {
      context.commit('DELWMSSRETURNCANLISTITEM', params) 
    },
    resetWmsReturnScanList(context) {
      context.commit('REACTRETURNlIST') 
    }
  },
};

export default stockManage;

